<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/WEB-INF/views/webPart/head.jsp"></jsp:include>
<title>下载计算器 - 呵Sever</title>
<style type="text/css">
</style>
<script type="text/javascript">
	function calculate(unit) {
		var TB = document.getElementById("TB");
		var GB = document.getElementById("GB");
		var MB = document.getElementById("MB");
		var KB = document.getElementById("KB");
		var Byte = document.getElementById("Byte");
		var bit = document.getElementById("bit");
		var speed = document.getElementById("speed");
		var percent = document.getElementById("percent");
		var time = document.getElementById("time");
		var val;

		if (unit == TB) {
			val = TB.value;
			GB.value = val * 1024;
			MB.value = val * 1024 * 1024;
			KB.value = val * 1024 * 1024 * 1024;
			Byte.value = val * 1024 * 1024 * 1024 * 1024;
			bit.value = val * 1024 * 1024 * 1024 * 1024 * 8;

			time.innerHTML = calTime(KB, percent, speed);
		}

		if (unit == GB) {
			val = GB.value;
			TB.value = val / 1024;
			MB.value = val * 1024;
			KB.value = val * 1024 * 1024;
			Byte.value = val * 1024 * 1024 * 1024;
			bit.value = val * 1024 * 1024 * 1024 * 8;

			time.innerHTML = calTime(KB, percent, speed);
		}

		if (unit == MB) {
			val = MB.value;
			TB.value = val / 1024 / 1024;
			GB.value = val / 1024;
			KB.value = val * 1024;
			Byte.value = val * 1024 * 1024;
			bit.value = val * 1024 * 1024 * 8;

			time.innerHTML = calTime(KB, percent, speed);
		}

		if (unit == KB) {
			val = KB.value;
			TB.value = val / 1024 / 1024 / 1024;
			GB.value = val / 1024 / 1024;
			MB.value = val / 1024;
			Byte.value = val * 1024;
			bit.value = val * 1024 * 8;

			time.innerHTML = calTime(KB, percent, speed);
		}

		if (unit == Byte) {
			val = Byte.value;
			TB.value = val / 1024 / 1024 / 1024 / 1024;
			GB.value = val / 1024 / 1024 / 1024;
			MB.value = val / 1024 / 1024;
			KB.value = val / 1024;
			bit.value = val * 8;

			time.innerHTML = calTime(KB, percent, speed);
		}

		if (unit == bit) {
			val = bit.value;
			TB.value = val / 1024 / 1024 / 1024 / 1024 / 8;
			GB.value = val / 1024 / 1024 / 1024 / 8;
			MB.value = val / 1024 / 1024 / 8;
			KB.value = val / 1024 / 8;
			Byte.value = val / 8;

			time.innerHTML = calTime(KB, percent, speed);
		}
	}

	function calTime(valKB, percent, speed) {
		var time = valKB.value * (1 - percent.value / 100) / speed.value;

		var day = Math.floor(time / 60 / 60 / 24);
		time = time / 60 / 60 / 24 - day;

		var hour = Math.floor(time * 24);
		time = time * 24 - hour;

		var minute = Math.floor(time * 60);
		time = time * 60 - minute;

		var second = time * 60;

		return day + "日" + hour + ":" + minute + ":" + second;
	}

	function selectSpeed() {
		var speedExample = document.getElementById("speedExample");
		var speed = document.getElementById("speed");
		speed.value = speedExample.value * 1024 / 8;
		calculate(KB);
	}
</script>
<style type="text/css">
	.form-group{
		display: inline-block;
		width:350px;
	}
</style>
</head>
<body>
	<jsp:include page="/WEB-INF/views/webPart/top.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/views/webPart/left.jsp"></jsp:include>
	<div class="mycol col-md-9 col-xs-11">
		<div class="main">
			<jsp:include page="/WEB-INF/views/pub/tools/webpart/breadcrumb.jsp">
				<jsp:param value="下载计算器" name="breadcrumbName"/>
			</jsp:include>
			<div class="mainItem">
				文件总大小：<br>
				<div class="form-group">
						<div class="input-group">
							<input class="form-control" onkeyup="calculate(TB)" id="TB">
							<div class="input-group-addon">TB</div>
						</div>
				</div>
				<div class="form-group">					
					<div class="input-group">
						<input class="form-control" onkeyup="calculate(GB)" id="GB">
						<div class="input-group-addon">GB</div>
					</div>
				</div>
				<div class="form-group">		
					<div class="input-group">
						<input class="form-control" onkeyup="calculate(MB)" id="MB">
						<div class="input-group-addon">MB</div>
					</div>
				</div>
				<div class="form-group">					
					<div class="input-group">
						<input class="form-control" onkeyup="calculate(KB)" id="KB">
						<div class="input-group-addon">KB</div>
					</div>
				</div>
				<div class="form-group">					
					<div class="input-group">
						<input class="form-control" onkeyup="calculate(Byte)" id="Byte">
						<div class="input-group-addon">Byte</div>
					</div>
				</div>
				<div class="form-group">					
					<div class="input-group">
						<input class="form-control" onkeyup="calculate(bit)" id="bit">
						<div class="input-group-addon">bit</div>
					</div>
				</div>
					<br> 下载完成度：<br> 
					<div class="form-group">					
						<div class="input-group">
							<input class="form-control" id="percent" onkeyup="calculate(KB)" value="0">
							<div class="input-group-addon">%</div>
						</div>
					</div>
				<br> 平均下载速度：<br> 
					<div class="form-group">					
						<div class="input-group">
							<input class="form-control" id="speed" onkeyup="calculate(KB)" value="256">
							<div class="input-group-addon">KB/s</div>
						</div>
					</div>
					<br>宽带（可以得到下载最高速度）：<br> 
					<select class="form-control"
						id="speedExample" style="display: block; width: 350px;"
						onchange="selectSpeed()">
						<option value="2">2Mbit</option>
						<option value="4">4Mbit</option>
						<option value="6">6Mbit</option>
						<option value="8">8Mbit</option>
						<option value="12">12Mbit</option>
					</select><br> <br> 下载所需时间：<br>
					<div id="time"></div>
					<br> <br> <br> 版本说明：<br> 
					V2.0 20150105 使用bootstrap样式 <br>
					V1.0 2014-06-26 22:06 创建
				</div>
			</div>
		</div>
		<jsp:include page="/WEB-INF/views/webPart/right.jsp"></jsp:include>
		<jsp:include page="/WEB-INF/views/webPart/footer.jsp"></jsp:include>
	</div>
</body>
</html>